{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "测试集评测代码，\n",
    "\n",
    "人工跑/机器跑？机器\n",
    "\n",
    "从excel加载测试集，构建成qa对（还要有问题类型），然后test_loop，需要调用dify的api来跑结果，\n",
    "\n",
    "不同的智能体权重等参数会有不同，\n",
    "\n",
    "得到每个智能体的总体得分、分问题类型的得分（可以分析出该智能体在哪些方面表现的优劣）、\n",
    "\n",
    "最后整个大智能体的总体得分，"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "1ba1787916dcf448"
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 调用智能体"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "ef22cfc88df2301d"
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[nltk_data] Downloading package wordnet to\n",
      "[nltk_data]     C:\\Users\\zc\\AppData\\Roaming\\nltk_data...\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001B[31m---------------------------------------------------------------------------\u001B[39m",
      "\u001B[31mKeyboardInterrupt\u001B[39m                         Traceback (most recent call last)",
      "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[4]\u001B[39m\u001B[32m, line 2\u001B[39m\n\u001B[32m      1\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mnltk\u001B[39;00m\n\u001B[32m----> \u001B[39m\u001B[32m2\u001B[39m \u001B[43mnltk\u001B[49m\u001B[43m.\u001B[49m\u001B[43mdownload\u001B[49m\u001B[43m(\u001B[49m\u001B[33;43m'\u001B[39;49m\u001B[33;43mwordnet\u001B[39;49m\u001B[33;43m'\u001B[39;49m\u001B[43m)\u001B[49m\n",
      "\u001B[36mFile \u001B[39m\u001B[32mD:\\code\\python\\THTF\\.venv\\Lib\\site-packages\\nltk\\downloader.py:774\u001B[39m, in \u001B[36mDownloader.download\u001B[39m\u001B[34m(self, info_or_id, download_dir, quiet, force, prefix, halt_on_error, raise_on_error, print_error_to)\u001B[39m\n\u001B[32m    765\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mshow\u001B[39m(s, prefix2=\u001B[33m\"\u001B[39m\u001B[33m\"\u001B[39m):\n\u001B[32m    766\u001B[39m     print_to(\n\u001B[32m    767\u001B[39m         textwrap.fill(\n\u001B[32m    768\u001B[39m             s,\n\u001B[32m   (...)\u001B[39m\u001B[32m    771\u001B[39m         )\n\u001B[32m    772\u001B[39m     )\n\u001B[32m--> \u001B[39m\u001B[32m774\u001B[39m \u001B[43m\u001B[49m\u001B[38;5;28;43;01mfor\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mmsg\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;129;43;01min\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mincr_download\u001B[49m\u001B[43m(\u001B[49m\u001B[43minfo_or_id\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mdownload_dir\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mforce\u001B[49m\u001B[43m)\u001B[49m\u001B[43m:\u001B[49m\n\u001B[32m    775\u001B[39m \u001B[43m    \u001B[49m\u001B[38;5;66;43;03m# Error messages\u001B[39;49;00m\n\u001B[32m    776\u001B[39m \u001B[43m    \u001B[49m\u001B[38;5;28;43;01mif\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[38;5;28;43misinstance\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mmsg\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mErrorMessage\u001B[49m\u001B[43m)\u001B[49m\u001B[43m:\u001B[49m\n\u001B[32m    777\u001B[39m \u001B[43m        \u001B[49m\u001B[43mshow\u001B[49m\u001B[43m(\u001B[49m\u001B[43mmsg\u001B[49m\u001B[43m.\u001B[49m\u001B[43mmessage\u001B[49m\u001B[43m)\u001B[49m\n",
      "\u001B[36mFile \u001B[39m\u001B[32mD:\\code\\python\\THTF\\.venv\\Lib\\site-packages\\nltk\\downloader.py:642\u001B[39m, in \u001B[36mDownloader.incr_download\u001B[39m\u001B[34m(self, info_or_id, download_dir, force)\u001B[39m\n\u001B[32m    638\u001B[39m     \u001B[38;5;28;01myield\u001B[39;00m FinishCollectionMessage(info)\n\u001B[32m    640\u001B[39m \u001B[38;5;66;03m# Handle Packages (delegate to a helper function).\u001B[39;00m\n\u001B[32m    641\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[32m--> \u001B[39m\u001B[32m642\u001B[39m     \u001B[38;5;28;01myield from\u001B[39;00m \u001B[38;5;28mself\u001B[39m._download_package(info, download_dir, force)\n",
      "\u001B[36mFile \u001B[39m\u001B[32mD:\\code\\python\\THTF\\.venv\\Lib\\site-packages\\nltk\\downloader.py:710\u001B[39m, in \u001B[36mDownloader._download_package\u001B[39m\u001B[34m(self, info, download_dir, force)\u001B[39m\n\u001B[32m    708\u001B[39m num_blocks = \u001B[38;5;28mmax\u001B[39m(\u001B[32m1\u001B[39m, info.size / (\u001B[32m1024\u001B[39m * \u001B[32m16\u001B[39m))\n\u001B[32m    709\u001B[39m \u001B[38;5;28;01mfor\u001B[39;00m block \u001B[38;5;129;01min\u001B[39;00m itertools.count():\n\u001B[32m--> \u001B[39m\u001B[32m710\u001B[39m     s = \u001B[43minfile\u001B[49m\u001B[43m.\u001B[49m\u001B[43mread\u001B[49m\u001B[43m(\u001B[49m\u001B[32;43m1024\u001B[39;49m\u001B[43m \u001B[49m\u001B[43m*\u001B[49m\u001B[43m \u001B[49m\u001B[32;43m16\u001B[39;49m\u001B[43m)\u001B[49m  \u001B[38;5;66;03m# 16k blocks.\u001B[39;00m\n\u001B[32m    711\u001B[39m     outfile.write(s)\n\u001B[32m    712\u001B[39m     \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m s:\n",
      "\u001B[36mFile \u001B[39m\u001B[32mD:\\developTools\\python\\Lib\\http\\client.py:479\u001B[39m, in \u001B[36mHTTPResponse.read\u001B[39m\u001B[34m(self, amt)\u001B[39m\n\u001B[32m    476\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m.length \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mand\u001B[39;00m amt > \u001B[38;5;28mself\u001B[39m.length:\n\u001B[32m    477\u001B[39m     \u001B[38;5;66;03m# clip the read to the \"end of response\"\u001B[39;00m\n\u001B[32m    478\u001B[39m     amt = \u001B[38;5;28mself\u001B[39m.length\n\u001B[32m--> \u001B[39m\u001B[32m479\u001B[39m s = \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mfp\u001B[49m\u001B[43m.\u001B[49m\u001B[43mread\u001B[49m\u001B[43m(\u001B[49m\u001B[43mamt\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m    480\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m s \u001B[38;5;129;01mand\u001B[39;00m amt:\n\u001B[32m    481\u001B[39m     \u001B[38;5;66;03m# Ideally, we would raise IncompleteRead if the content-length\u001B[39;00m\n\u001B[32m    482\u001B[39m     \u001B[38;5;66;03m# wasn't satisfied, but it might break compatibility.\u001B[39;00m\n\u001B[32m    483\u001B[39m     \u001B[38;5;28mself\u001B[39m._close_conn()\n",
      "\u001B[36mFile \u001B[39m\u001B[32mD:\\developTools\\python\\Lib\\socket.py:707\u001B[39m, in \u001B[36mSocketIO.readinto\u001B[39m\u001B[34m(self, b)\u001B[39m\n\u001B[32m    705\u001B[39m \u001B[38;5;28;01mwhile\u001B[39;00m \u001B[38;5;28;01mTrue\u001B[39;00m:\n\u001B[32m    706\u001B[39m     \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[32m--> \u001B[39m\u001B[32m707\u001B[39m         \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_sock\u001B[49m\u001B[43m.\u001B[49m\u001B[43mrecv_into\u001B[49m\u001B[43m(\u001B[49m\u001B[43mb\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m    708\u001B[39m     \u001B[38;5;28;01mexcept\u001B[39;00m timeout:\n\u001B[32m    709\u001B[39m         \u001B[38;5;28mself\u001B[39m._timeout_occurred = \u001B[38;5;28;01mTrue\u001B[39;00m\n",
      "\u001B[36mFile \u001B[39m\u001B[32mD:\\developTools\\python\\Lib\\ssl.py:1252\u001B[39m, in \u001B[36mSSLSocket.recv_into\u001B[39m\u001B[34m(self, buffer, nbytes, flags)\u001B[39m\n\u001B[32m   1248\u001B[39m     \u001B[38;5;28;01mif\u001B[39;00m flags != \u001B[32m0\u001B[39m:\n\u001B[32m   1249\u001B[39m         \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[32m   1250\u001B[39m           \u001B[33m\"\u001B[39m\u001B[33mnon-zero flags not allowed in calls to recv_into() on \u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[33m\"\u001B[39m %\n\u001B[32m   1251\u001B[39m           \u001B[38;5;28mself\u001B[39m.\u001B[34m__class__\u001B[39m)\n\u001B[32m-> \u001B[39m\u001B[32m1252\u001B[39m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mread\u001B[49m\u001B[43m(\u001B[49m\u001B[43mnbytes\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mbuffer\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m   1253\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[32m   1254\u001B[39m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28msuper\u001B[39m().recv_into(buffer, nbytes, flags)\n",
      "\u001B[36mFile \u001B[39m\u001B[32mD:\\developTools\\python\\Lib\\ssl.py:1104\u001B[39m, in \u001B[36mSSLSocket.read\u001B[39m\u001B[34m(self, len, buffer)\u001B[39m\n\u001B[32m   1102\u001B[39m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[32m   1103\u001B[39m     \u001B[38;5;28;01mif\u001B[39;00m buffer \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[32m-> \u001B[39m\u001B[32m1104\u001B[39m         \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_sslobj\u001B[49m\u001B[43m.\u001B[49m\u001B[43mread\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43mlen\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mbuffer\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m   1105\u001B[39m     \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[32m   1106\u001B[39m         \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m._sslobj.read(\u001B[38;5;28mlen\u001B[39m)\n",
      "\u001B[31mKeyboardInterrupt\u001B[39m: "
     ]
    }
   ],
   "source": [
    "import nltk\n",
    "nltk.download('wordnet')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-25T06:37:07.806998Z",
     "start_time": "2025-04-25T06:36:57.505242Z"
    }
   },
   "id": "ffce55ce377cfa2e",
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "⏰ **当前时间** ⏰  \n",
      "亲～现在是**2025年4月25日 上午09:31**啦！  \n",
      "记得给自己泡杯茶，开启元气满满的一天哦～ 🌞  \n",
      "\n",
      "（贴心小提示：距离周末还有2天，冲鸭！💪）\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "\n",
    "# 读取 JSON 文件\n",
    "with open('data/dify_answers.json', 'r', encoding='utf-8') as f:\n",
    "    data = json.load(f)\n",
    "\n",
    "# 提取 answer 字段组成数组\n",
    "answers = [item['answer'] for item in data]\n",
    "\n",
    "# 打印结果\n",
    "print(answers[1])\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-25T06:44:35.269197Z",
     "start_time": "2025-04-25T06:44:35.261200Z"
    }
   },
   "id": "5d854fe7fdf2f93b",
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "response = requests.get(\"http://10.10.252.225:8000\", timeout=5)\n",
    "print(response.status_code)  # 如果不是401，说明端口可达"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-30T03:10:33.299164Z",
     "start_time": "2025-04-30T03:10:32.856813Z"
    }
   },
   "id": "6b49f96973e173bc",
   "execution_count": 1
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "29cf38ed9047f8e2"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
